package com.example.mygame.controller;

import com.example.mygame.model.BackupTask;
import com.example.mygame.model.BackupTaskDetail;
import com.example.mygame.model.EquipmentInfo;
import com.example.mygame.service.BackupService;
import com.example.mygame.utils.ReadCsvUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("base/equipment/v1")
@CrossOrigin(origins = "*")
public class EquilpmentController {

    @Autowired
    private BackupService backupService;

    @GetMapping(value="/list")
    @ResponseBody List<EquipmentInfo> getList(){//返回json 数据
        return ReadCsvUtils.read("equipment1.csv");
    }

    @PostMapping(value="/save")
    @ResponseBody boolean saveList(@RequestBody  List<EquipmentInfo> list) throws IOException {//返回json 数据
        return ReadCsvUtils.save(list,"equipment1.csv");
    }

    @GetMapping(value="/list2")
    @ResponseBody List<BackupTask> getList2(){//返回json 数据
        return ReadCsvUtils.read2("equipment2.csv");
    }

    @PostMapping(value="/save2")
    @ResponseBody boolean saveList2(@RequestBody  List<BackupTask> list) throws IOException {//返回json 数据
        return ReadCsvUtils.save2(list,"equipment2.csv");
    }

    @PostMapping(value="/listDetail")
    @ResponseBody
    BackupTaskDetail getList3(@RequestBody Map name) {//返回json 数据
        return backupService.getDetail(name.get("name").toString());
    }

}
